package _13并发修改异常_了解;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;

public class Demo {
    public static void main(String[] args) {
        Collection<String> collection = new ArrayList<>();


        //集合添加元素 add
        collection.add("java");
        collection.add("python");
        collection.add("c++");

        Iterator<String> iterator = collection.iterator();

        while (iterator.hasNext()){
            String next = iterator.next();
            if (next=="java"){
               //collection.remove(next);//ConcurrentModificationException,原因：一边查询一边修改
                iterator.remove();

            }

        }
        System.out.println(collection);


    }
}
